package com.ideviu.webapp.action;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ideviu.model.Anuncio;
import com.ideviu.service.AnuncioManager;

@Component("anuncioList")
@Scope("session")
public class AnuncioList extends BasePage implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String query;
	@Autowired
	private AnuncioManager anuncioManager;
    
    public void setAnuncioManager(AnuncioManager anuncioManager) {
        this.anuncioManager = anuncioManager;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public String getQuery() {
        return query;
    }

    public AnuncioList() {
        setSortColumn("id"); // sets the default sort column
    }

    public List<Anuncio> getAnuncios() {
        if (query != null && !"".equals(query.trim())) {
            return anuncioManager.search(query, Anuncio.class);
        } else {
            return sort(anuncioManager.getAll());
        }
    }

    public String search() {
        return "success";
    }
}